<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\ScenicDivination;
use \App\Models\Divination;
use \App\Models\ScenicArea;
use \App\Models\Category;
use Encore\Admin\Facades\Admin;
use App\Services\MakeProductThumbnail\MakeProductThumbnail;
use App\Admin\Actions\DivinationAction\MakeDeepThink;

class ScenicDivinationController extends AdminController
{
    protected $title = '银子岩配置';
    
    protected function grid()
    {
        $grid = new Grid(new ScenicDivination());

	    $grid->disableExport();
	
	    $grid->column('id', 'ID');
	    $grid->column('title', '卜卦标题')->display(function () {
		    return $this->divination->title;
	    });

	    $grid->column('uname', '人物名称');
	  
	    $grid->column('image', '图片')->lightbox(['width' => 50, 'height' => 50]);
	   
	    $grid->column('created_at', '创建时间')->display(function () {
		    return $this->created_at->toDatetimeString();
	    });
	
	    $grid->disableRowSelector();
	    $this->gridActions($grid);
        return $grid;
    }

     protected function gridActions(Grid $grid)
    {
	    $grid->actions(function (Grid\Displayers\Actions $actions) {
	    	//$actions->disableDelete();

	    	/*if (in_array(Admin::user()->id, [1,2])) {
		    	$actions->add(new MakeDeepThink());

 			}*/
		    
	    });
    }
	
	 protected function detail($id)
    {
        $show = new Show(ScenicDivination::findOrFail($id));
        return $show;
    }
	
    protected function form()
    {
        $form = new Form(new ScenicDivination());

        $form->select('scenic_area_id', '景区')->options(ScenicArea::all()->pluck('name', 'id'))
            ->rules('required');
        $form->image('image', '图片')->uniqueName()->help('NOTE：保证清晰的前提下尽可能压缩体积');

        $form->fieldset('本命财神模块', function (Form $form) {
	        $form->text('uname', '本命财神')->rules('required');
	        $form->text('tag', '人物称号');
	        $form->text('hangye', '生财行业');
	        $form->text('category', '财运类型');
	        $form->textarea('cqgy', '财气感应');
		    $form->textarea('profile', '财运档案')->rules('required');
		    $form->select('divination_id', '财易卦象')->options(Divination::all()->pluck('title', 'id'))
	            ->rules('required');
		    $form->textarea('content', '财运易理')->rules('required');
		    $form->text('words', '财运吉语');
		});   	
         $form->fieldset('值日财神模块', function (Form $form) {
		   	$form->text('direction', '生财方位');
		   	$form->text('armoury', '行业锦囊');
		    $form->text('dressing', '穿搭开运');
		    $form->textarea('precautions', '注意事项');
		});   	

	   /* $form->text('revelation', '行动启示');
	   $form->text('moment', '时机天机');*/
	    
	    $this->formSaved($form);
        return $form;
    }

    protected function formSaved(Form $form)
	{
		$form->saved(function () use ($form) {
			
			
			//app(MakeProductThumbnail::class, ['divination' => $form->model()])->make();
		});
	}
}
